#include <AMSI.h>

#include <Ice/Ice.h>

AMSI::AMSI
(std::string platformName)
{
  _desc.name = platformName;
}
 
AMSI::
~AMSI()
{
}

void
AMSI::_cpp_register
(const FIPA::AgentPrx& aid,
 const Ice::Current& curr)
{
  IceUtil::Mutex::Lock lock(_m);

  if (_agents.find(aid->ice_getIdentity()) == _agents.end())
    _agents[aid->ice_getIdentity()] = aid;
  else
    throw FIPA::AgentExists();
}

void
AMSI::deregister
(const Ice::Identity& id, 
 const Ice::Current& curr)
{
  IceUtil::Mutex::Lock lock(_m);
  
  _agents.erase(id);
}
 
FIPA::AgentPrx
AMSI::search
(const Ice::Identity& id, 
 const Ice::Current& curr)
{
  IceUtil::Mutex::Lock lock(_m);

  return _agents[id];
}
 
FIPA::ApDescription
AMSI::getDescription
(const Ice::Current& curr)
{
  return _desc;
}
